{% extends 'base.html' %}
{% load crispy_forms_tags %} {# Load crispy forms tags #}

{% block title %}用户登录 - {{ block.super }}{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-6 col-lg-4">
        <div class="card shadow-sm">
            <div class="card-body">
                <h2 class="card-title text-center mb-4">用户登录</h2>
                {% if form.errors %}
                    <div class="alert alert-danger" role="alert">
                        您的用户名和密码不匹配，请重试。
                    </div>
                {% endif %}

                {% if next %}
                    {% if user.is_authenticated %}
                    <div class="alert alert-warning" role="alert">
                        您的账户无权访问此页面。要继续，请使用有权访问的账户登录。
                    </div>
                    {% else %}
                    <div class="alert alert-info" role="alert">
                        请登录以查看此页面。
                    </div>
                    {% endif %}
                {% endif %}

                <form method="post" action="{% url 'login' %}">
                    {% csrf_token %}
                    {{ form|crispy }} {# Render the form using crispy #}
                    <input type="hidden" name="next" value="{{ next|default:'' }}"> {# Pass redirect URL #}
                    <div class="d-grid gap-2">
                        <button type="submit" class="btn btn-success btn-block">登录</button>
                    </div>
                </form>
                <p class="mt-3 text-center">
                    <a href="#">忘记密码?</a> {# Add password reset URL if implemented #}
                </p>
                 {# Add link to registration page if implemented #}
                 {# <p class="text-center">没有账户? <a href="{% url 'register' %}">立即注册</a></p> #}
            </div>
        </div>
    </div>
</div>
{% endblock %}